package com.itheima.publisher.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.Optional;

@Configuration
@RequiredArgsConstructor
@Slf4j
public class MqConfig {
    public final RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void init() {
        rabbitTemplate.setReturnsCallback(returnCallback -> {
            log.error("触发return callback,");
            log.debug("消息发送失败，交换机：{}，路由键：{}，消息：{}，返回码：{}，返回文本{}",
                    returnCallback.getExchange(),
                    returnCallback.getRoutingKey(),
                    returnCallback.getMessage(),
                    returnCallback.getReplyCode(),
                    returnCallback.getReplyText());
//            log.debug("消息发送失败，交换机：{}，路由键：{}，消息：{}",
//                    returnCallback.getExchange(),
//                    returnCallback.getRoutingKey(),
//                    returnCallback.getMessage());

//            log.debug("消息发送失败，返回码：{}", returnCallback.getReplyCode());
//            log.debug("消息发送失败，返回文本{}", returnCallback.getReplyText());
        });
    }
}
